<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
 <meta charset="utf-8">
 <title>组织管理</title>
 <meta name="renderer" content="webkit">
 <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
 <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
 <link rel="stylesheet" href="../layui/css/layui.css" th:href="@{../layui/css/layui.css}" media="all">
<link href="favicon.ico" rel="shortcut icon">
</head>
<script th:src="@{../../layui/layui.js}" charset="utf-8"></script>

<body>
<table class="layui-hide" id="test" lay-filter="test"></table>
<!-- 头部工具栏 -->
<script type="text/html" id="toolbarDemo">
  <div class="layui-btn-container">
    <button class="layui-btn layui-btn-sm" lay-event="getCheckData">获取选中行数据</button>
    <button class="layui-btn layui-btn-sm" lay-event="getCheckLength">添加</button>
  </div>
</script>
<!-- 行工具栏 -->
<script type="text/html" id="barDemo">
  <a class="layui-btn layui-btn-xs" lay-event="edit"><i class="layui-icon layui-icon-edit"></i>编辑</a>
  <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del"><i class="layui-icon layui-icon-delete"></i>删除</a>
</script>
<script>
layui.use(['table','form'], function(){
	  var table = layui.table;
	  var form = layui.form;
//执行一个 table 实例
	table.render({
	  elem: '#test'
	  ,height: 'full-80'
	  ,url: 'list' //数据接口
	  ,even:true
	  ,title: '组织表'
	  ,toolbar:'#toolbarDemo'  //开启工具栏
	  ,cols: [
		  [ //表头
		{type: 'checkbox', fixed: 'left'}
	    ,{field: 'oid', title: 'ID',width:100, sort: true, fixed: 'left'}
	    ,{field: 'oname', title: '组织名称'}
	    ,{field: 'bname', title: '书记姓名'}
	    ,{field: 'linkman', title: '组织联系人'}
	    ,{field: 'ophone', title: '组织联系人电话'}
	    ,{field: 'otype', title: '类型'}
	    ,{field: 'address', title: '地址'}
	    ,{field: 'adminid', title: '管理员id'}
	    ,{field: 'parentId', title: '上级所属组织'}
	    ,{field: 'ostid', title: '组织状态'}
	    ,{field: 'osgid', title: '组织级别'}
	    ,{fixed: 'right', title:'操作', toolbar: '#barDemo'}
	  ]
		]
	});
	//头工具栏事件
	  table.on('toolbar(test)', function(obj){
	    var checkStatus = table.checkStatus(obj.config.id);
	    switch(obj.event){
	      case 'getCheckData':
	        var data = checkStatus.data;
	        layer.alert(JSON.stringify(data));
	      break;
	      case 'getCheckLength':
	        var data = checkStatus.data;
	        layer.msg('选中了：'+ data.length + ' 个');
	      break;
	    };
	  });
	//监听行工具事件
	  table.on('tool(test)', function(obj){
	    var data = obj.data;
	    //console.log(obj)
	    if(obj.event === 'del'){
	      layer.confirm('真的删除行么', function(index){
	        obj.del();
	        layer.close(index);
	      });
	    } else if(obj.event === 'edit'){
			form.val("formTest",data);
			var oname = data.oname;
			if(oname=="管理员"){
				layui.$("#name").val(1);
			}else if(oname=="党工委"){
				layui.$("#name").val(2);
			}else if(oname=="党委"){
				layui.$("#name").val(3);
			}else if(oname=="党总支"){
				layui.$("#name").val(4);
			}else if(oname=="党支部"){
				layui.$("#name").val(5);
			}
			
			var state=data.ostid;
	    	if(state=="禁用"){
	    		layui.$("#sel").val(2);
	    	}else{
	    		layui.$("#sel").val(1);
	    	} 
	    	form.render('select','formTest'); 
			layer.open({
				type:1,
				title:'修改权限',
				area:'800px',
				anim: 1,
				skin: 'layui-layer-molv',
				content:layui.$("#update")
			})
	    };
	  });
});
</script>
<form id="update" class="layui-form layui-form-pane" action="update" lay-filter="formTest" method="post" hidden="true" style="height:400px">
 	<div class="layui-form-item">
	  <label class="layui-form-label">用户权限</label>
	    <div class="layui-input-block" lay-filter="aihao">
		   <select name="permission">
		      	<option value="">请选择</option>
		        <option value="1">党员</option>
		        <option value="2">党支部管理员</option>
		        <option value="3">党总支管理员</option>
		        <option value="4">党委管理员</option>
		        <option value="5">党工委管理员</option>
		        <option value="6">管理员</option>
		    </select>
    	</div>
   </div>
 	<div class="layui-form-item">
	  <label class="layui-form-label">所属组织</label>
	    <div class="layui-input-block" lay-filter="aihao">
		   <select name="oname" id="name">
		      	<option value="">请选择</option>
		        <option value="1">管理员</option>
		        <option value="2">党工委</option>
		        <option value="3">党委</option>
		        <option value="4">党总支</option>
		        <option value="5">党支部</option>
		    </select>
    	</div>
   </div>
   <div class="layui-form-item">
    <label class="layui-form-label" >用户状态</label>
    <div class="layui-input-block" lay-filter="aihao">
      <select name="ostid" id="sel" >
      	<option value="">请选择</option>
        <option value="1">启用</option>
        <option value="2">禁止</option>
      </select>
    </div>
  </div>
  <div class="layui-form-item">
    <div class="layui-input-block">
      <button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
      <button type="reset" class="layui-btn layui-btn-primary">重置</button>
    </div>
  </div>
</form>
</body>
</html>